<extend name="Public:base" />

<block name="content">

<div class="page-header">
<a href="{:U('Goods/add')}" class="btn btn-primary">新增</a>
<span href="{:U('Goods/copy_goods')}" class="btn btn-primary copy">复制</span>
</div>	
	
<table class="table table-striped table-bordered table-hover search-form">
	<thead>
		<th><input name="name" type="text" placeholder="输入商品名称" value="{:I('name')}" /></th>
		<th>    				
			<select name="category">
				<option value="">-选择分类-</option>
				<volist name="category" id="v" >
					<option <?php if(isset($get_category)&&($get_category==$v['id'])){echo ' selected="selected"';} ?> value="{$v.id}">{$v.name}</option>
				</volist>	
			</select>
		</th>	
		<th>    				
			<select name="status">
				<option value="">-选择状态-</option>				
				<option <?php if(isset($get_status)&&($get_status==1)){echo ' selected="selected"';} ?> value="1">启用</option>
				<option <?php if(isset($get_status)&&($get_status==0)){echo ' selected="selected"';} ?> value="0">停用</option>
			</select>
		</th>
		<th>
			<a class="btn btn-primary" href="javascript:;" id="search" url="{:U('Goods/index')}">查询</a>
		</th>
	</thead>
</table>	
	

	
<div class="row">
	<div class="col-xs-12">	
		<div class="table-responsive">
			<table id="table" class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<th class="center">
							<label>
								<input type="checkbox" class="ace check-all" />
								<span class="lbl"></span>
							</label>
						</th>											
						<th>ID</th>
						<th>图片</th> 
						<th>商品名称</th> 
						<th>分类</th> 
						<th>价格</th>
						<th>数量</th>
						<th>状态</th>						
						<th>操作</th>				
					</tr>
				</thead>
				<tbody>
						<volist name="list" id="v" empty="$empty">
						<tr>		
							<td class="center">
							<label>
								<input class="ace ids" type="checkbox" name="id[]" value="{$v.goods_id}"/>
								<span class="lbl"></span>
							</label>
							</td>				
							<td>{$v.goods_id}</td>
							<td>
								<?php if($v['image']){ ?>
								<img src="__ROOT__/{$v.image}" />
								<?php }else{ ?>
								<img src="__ROOT__/Common/image/no_image_50x50.jpg" />
								<?php } ?>	
							</td>
							<td>{$v.name}</td>
							<td><?php echo get_goods_category_name($v['category_id']); ?></td>
							<td>{$v.price}</td>
							<td>{$v.quantity}</td>
							<td>
								<switch name="v.status">
									<case value="1"><span class="green bold">启用</span></case>
									<case value="0"><span class="red">停用</span></case>
								</switch>
							</td>
							<td>
								<a  class="btn btn-xs btn-info" href='{:U("Goods/edit",array("id"=>$v["goods_id"]))}'>
									<i class="icon-edit bigger-120"></i>
								</a> 
								<a class="delete btn btn-xs btn-danger" href='{:U("Goods/del",array("id"=>$v["goods_id"]))}' >
									<i class="icon-trash bigger-120"></i>
								</a>
							</td>
						</tr>
						</volist>	
						
						<tr>
							<td colspan="20" class="page">{$page}</td>
						</tr>
				</tbody>
				
			</table>
		</div>
	</div>
</div>
</block>
<block name="javascript">
<script>
$(function(){
	
	$("#search").click(function () {
        var url = $(this).attr('url');
        var query = $('.search-form').find('input,select').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
        query = query.replace(/^&/g, '');
        if (url.indexOf('?') > 0) {
            url += '&' + query;
        } else {
            url += '?' + query;
        }
        window.location.href = url;
    });
	
	$('.copy').click(function(){
		$.ajax({
		url: "{:U('Goods/copy_goods')}",
		type: 'post',
		data: $('input:checked'),
		dataType: 'json',
		beforeSend: function() {
			$('.copy').attr('disabled', true);
			$('.copy').after('<span class="wait">&nbsp;<img src="__IMG__/loading.gif" alt="" /></span>');
		},	
		complete: function() {
			$('.copy').attr('disabled', false); 
			$('.wait').remove();
		},			
		success: function(json) {
			$('.warning, .error').remove();
					
			if (json['redirect']) {				
				
				location = json['redirect']
								
			} 
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert('修改失败');
		}
	});	
	});
});		
</script>
</block>